package com.jbm.enterapplication.userlogin.mode

import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.utlisclass.HttpNet
import rx.Observable
import rx.Observer

/**
 * Created by 家帮忙 on 2017/9/4.
 */
class User_mode_Login :User_mode_Login_In<String> {

    override fun getWXLogin(name: String, pwd: String,opid:String, onclick: InterfaceMa<String>) {//微信登录

        HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe <String>{OrLogin->
            OrLogin.onNext(HttpNet.getInstans().getOhInter().Login(name,pwd,opid))
        })).subscribe(object :Observer<String>{
            override fun onCompleted() {

            }

            override fun onNext(t: String?) {
                if (t== "Login OK") {
                    onclick.onSuccess("1",true)
                } else if (t == "FAILED") {

                    onclick.setError("登录失败请检查网络",false)
                    //登录超时

                } else {
                    //没有注册的用户
                    onclick.onSuccess("2",true)
//                    startActivity(Intent(this@LoginActivity, RegisterActivity::class.java))

                }
            }

            override fun onError(e: Throwable?) {

            }

        })





    }


    override fun getUserLogin(name: String, pwd: String, onclick: InterfaceMa<String>) {//手机号登录
     HttpNet.getInstans().obsevice(Observable.create(Observable.OnSubscribe <String>{OrLogin->
        OrLogin.onNext( HttpNet.getInstans().getOhInter().Login(name,pwd))
     })).subscribe(object :Observer<String>{
         override fun onNext(t: String?) {
             if (t == "Login OK") {
                 onclick.onSuccess("1",true)
             } else if (t == "FAILED") {
                 onclick.setError("2",false)
             } else if (t == "request timeout") {
                 onclick.setError("3",false)
             } else if (t == "Not Connect") {
                 onclick.setError("4",false)
             } else {
                 onclick.setError(t!!,false)
             }

         }
         override fun onCompleted() {

         }
         override fun onError(e: Throwable?) {

         }

     })









    }
}